package com.cityp.controller;

import com.cityp.bean.ResultBean;
import com.cityp.bean.sceneAndTool;
import com.cityp.bean.tool;
import com.cityp.service.toolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping(value = "/moduleManage")
public class toolManageController {
    /**
     * 查看所有工具
     */
    @Autowired
    private toolService toolService;
    @RequestMapping(value = "/toolView",method = RequestMethod.GET)
    @ResponseBody
    public ResultBean viewAll(){
        List<tool> res= toolService.viewAll();
        if (res==null) return ResultBean.err( "出现错误，请重试");
        else return ResultBean.success("查询成功",res);
    }

    /**
     * 添加一个工具
     */
    @RequestMapping(value = "/addtool",method = RequestMethod.POST)
    public ResultBean addOne(@RequestBody tool tool){
        int res= toolService.addOne(tool);
        if (res==0) return ResultBean.err("出现错误，请重试");
        else return ResultBean.success( "添加成功",res);
    }

    /**
     * 删除一个工具
     */
    @RequestMapping(value = "/deltool",method =RequestMethod.GET)
    public ResultBean delOne(@RequestParam int id){
        int res= toolService.delOne(id);
        if (res==0) return ResultBean.err("出现错误，请重试");
        else return ResultBean.success( "删除成功",res);
    }

    /**
     * 修改一个工具
     */
    @RequestMapping(value = "/changetool",method = RequestMethod.POST)
    public ResultBean changeTool(@RequestBody sceneAndTool sceneAndTool){
        int res= toolService.changeOne(sceneAndTool.getId(), sceneAndTool.getType(), sceneAndTool.getPara());
        if (res==0) return ResultBean.err("出现错误，请重试");
        else return ResultBean.success("修改成功",res);
    }

    String a = new String("aa");
    StringBuffer b;
}
